package com.example.mapper;

import com.example.entity.Praise;
import org.apache.ibatis.annotations.*;

@Mapper
public interface PraiseMapper {

    /**
     * 点赞
     */
    @Insert("insert into praise(fid,user_id) values (#{fid},#{userId})")
    void insert(Praise praise);

    /**
     * 取消点赞
     */
    @Delete("delete from praise where fid = #{fid} and user_id = #{userId}")
    void deleteByFidAndUserId(@Param("fid") Integer fid, @Param("userId") Integer userId);

    /**
     * 查询用户点赞数据（用来判断用户是否点赞）
     */
    @Select("select * from praise where fid = #{fid} and user_id = #{userId}")
    Praise selectByFidAndUserId(@Param("fid") Integer fid, @Param("userId") Integer userId);

    /**
     * 查询当前帖子的点赞量
     */
    @Select("select count(*) from praise where fid = #{fid}")
    Integer selectCount(Integer fid);
}
